<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page import="com.smarthome.web.property.utils.UserHolder"  %>
<script type="text/javascript">

	$(function() {
		var residenceId = '${residenceId}';
		showXiyi(residenceId);
		//showXiyi(8);
		CommUtil.Area.regetst({province :'desProvinceId' , city:'desCityId' , district:'desAreaId'});
		
		$('.mobile').blur(function(){
			  var mobile = $(this).val();
			  var thisName = $(this).attr('name');
			  if($(this).validatebox('isValid')) {
				 // alert(mobile);
				  $.ajax({
						type:'post',
						url:'/sendCourierController/getHistoryAccountInfo',
						data:{'mobile':mobile},
						success:function(result) {
							if(thisName == 'phone') {
								if(result.id != null) {
									$('#desAccountId').val(result.id);
								}
								if(result.areaDetail != null && result.areaDetail != "" && $('#desAreaDetail').val() == "") {
									$('#desAreaDetail').val(result.areaDetail);
								}
								if(result.name != null && result.name != "" && ($('#desAccountName').val() == "" || $('#desAccountName').val() == "客户")) {
									$('#desAccountName').val(result.name);
								}
								if(result.areaId != null) {
									CommUtil.Area.regetst({province :'desProvinceId' , city:'desCityId' , district:'desAreaId',districtId:result.areaId});
								} 
							}
						},
						dataType:'json'
					});
			  }
		});
		
		
		// 小区
		/* $.ajax({
			type:'post',
			url:'/residenceController/combobox',
			data:{},
			success:function(result) {
				$('#residenceId').combobox({
					data : result,
					valueField:'value',   
				    textField:'text',
				    panelHeight:'auto',
				    onSelect : function(a){
				    	//alert(a.value);
				    	showXiyi(a.value);
						//$('#companyId').combobox('reload','/companyLaundryController/getCombobox?residenceId=' + a.value);
						//$('#companyId').combobox('clear');
					}
				});
			},
			dataType:'json'
		}); */
		

		
		//保存操作
		$('#form').form({
			url : '/xiyiOrderController/add',
			onSubmit : function() {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				var isValid = $(this).form('validate');
				if (!isValid) {
					parent.$.messager.progress('close');
				}
				return isValid;
			},
			success : function(result) {
				parent.$.messager.progress('close');
				result = $.parseJSON(result);
				if (result.success) {
					parent.$.messager.alert('提示',result.msg,'info');
					parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_treeGrid这个对象，是因为resource.jsp页面预定义好了
					parent.$.modalDialog.handler.dialog('close');
				}else{
					parent.$.messager.alert('提示',result.msg,'info');
				}
			}
		});
		parent.$.messager.progress('close'); 
	});
	
	function showXiyi(residenceId){
		//洗衣店下拉
		$.ajax({
			type:'post',
			url:'/companyLaundryController/getCombobox?residenceId='+residenceId,
			data:{},
			success:function(result) {
				$('.companyId').combobox({
					data : result,
					valueField:'value',   
				    textField:'text',
				    panelHeight:'auto'
				});
			},
			dataType:'json'
		});
	}
	
	
	/**
	* 实时动态强制更改用户录入
	* arg1 inputObject
	**/
	function amount(th){
	    var regStrs = [
	        ['^0(\\d+)$', '$1'], //禁止录入整数部分两位以上，但首位为0
	        ['[^\\d\\.]+$', ''], //禁止录入任何非数字和点
	        ['\\.(\\d?)\\.+', '.$1'], //禁止录入两个以上的点
	        ['^(\\d+\\.\\d{2}).+', '$1'] //禁止录入小数点后两位以上
	    ];
	    for(i=0; i<regStrs.length; i++){
	        var reg = new RegExp(regStrs[i][0]);
	        th.value = th.value.replace(reg, regStrs[i][1]);
	    }
	}
	 
	/**
	* 录入完成后，输入模式失去焦点后对录入进行判断并强制更改，并对小数点进行0补全
	* arg1 inputObject
	* 这个函数写得很傻，是我很早以前写的了，没有进行优化，但功能十分齐全，你尝试着使用
	* 其实有一种可以更快速的JavaScript内置函数可以提取杂乱数据中的数字：
	* parseFloat('10');
	**/
	function overFormat(th){
	    var v = th.value;
	    if(v === ''){
	        v = '0.00';
	    }else if(v === '0'){
	        v = '0.00';
	    }else if(v === '0.'){
	        v = '0.00';
	    }else if(/^0+\d+\.?\d*.*$/.test(v)){
	        v = v.replace(/^0+(\d+\.?\d*).*$/, '$1');
	        v = inp.getRightPriceFormat(v).val;
	    }else if(/^0\.\d$/.test(v)){
	        v = v + '0';
	    }else if(!/^\d+\.\d{2}$/.test(v)){
	        if(/^\d+\.\d{2}.+/.test(v)){
	            v = v.replace(/^(\d+\.\d{2}).*$/, '$1');
	        }else if(/^\d+$/.test(v)){
	            v = v + '.00';
	        }else if(/^\d+\.$/.test(v)){
	            v = v + '00';
	        }else if(/^\d+\.\d$/.test(v)){
	            v = v + '0';
	        }else if(/^[^\d]+\d+\.?\d*$/.test(v)){
	            v = v.replace(/^[^\d]+(\d+\.?\d*)$/, '$1');
	        }else if(/\d+/.test(v)){
	            v = v.replace(/^[^\d]*(\d+\.?\d*).*$/, '$1');
	            ty = false;
	        }else if(/^0+\d+\.?\d*$/.test(v)){
	            v = v.replace(/^0+(\d+\.?\d*)$/, '$1');
	            ty = false;
	        }else{
	            v = '0.00';
	        }
	    }
	    th.value = v; 
	}
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false" title="" style="overflow: hidden;">
		<form id="form" method="post">
			<table class="table table-hover table-condensed">
				<tr>
					<th>洗衣店</th>
					<td ><input name="companyId" class="span2 companyId"  data-options="required:true"  /></td>
					<th>衣服编号</th>
					<td ><input name="outBizNum" type="text" class="easyui-validatebox span2" data-options="required:true" ></td>
				</tr>
				<tr>
					<th>客户名称</th><!-- style="width: 375px; height: 29px;" -->
					<td ><input id="kh_name"  name="kh_name" /></td>
					<th>手机号码</th><!-- style="width: 375px; height: 29px;" -->
					<td ><input id="phone"  name="phone" placeholder="请输入手机号" class="easyui-validatebox span2 mobile" data-options="validType:'isPhoneNumber'" required="required" /></td>
				</tr>
				<tr>
					<th>客户地址</th>
					<td colspan="3">
						<input id="desProvinceId" style="width: 148px">
						<input id="desCityId" style="width: 148px">
						<input name="desAreaId"  id="desAreaId" style="width: 148px">
					</td>
				</tr>
				<tr>
					<th>街道门牌</th>
					<td colspan="3">
						<input name="desAreaDetail" id="desAreaDetail" type="text" style="width: 470px" class="easyui-validatebox" required="required"/>
					</td>
				</tr>
				<tr>
					<th>订单费用</th>
					<td ><input name="amountStr" type="text" placeholder="请输入订单费用" class="easyui-validatebox span2" data-options="required:true" onKeyUp="amount(this)" onBlur="overFormat(this)"></td>
					<th>订单类型</th>
					<td ><input  type="radio" name="courierType" value="1" checked="true" />普通&nbsp;&nbsp;&nbsp;&nbsp;
						<input  type="radio" name="courierType" value="2" />及时
					</td>
				</tr>
				<tr>
					<th>备注信息</th>
					<td colspan="3"><textarea name="remark" id="remark"  style="width:90%; height: 89px;"></textarea></td>
				</tr>
			</table>
		</form>
	</div>
</div>